<?php defined('SYSPATH') OR die('No direct access allowed.');

	print form::open(NULL,array('method'=>'get'));
	print form::open_fieldset();

	print form::legend('Wybierz kierunek i semestr, który chcesz obejrzeć:');
	
	print '<p>';
	$kierunek = array('informatyka'=>'Informatyka');
	print form::label('select-kierunek','<strong>Kierunek</strong>');
	print form::dropdown('select-kierunek',$kierunek);
	print '</p>';

	print '<p>';
	$studia = array('stacjonarne-inz'=>'I stopnia, stacjonarne');
	print form::label('select-studia','<strong>Studia</strong>');
	print form::dropdown('select-studia',$studia);
	print '</p>';

	$semestr = array();
	$default = ($_GET)?(int)$this->input->get("select-semestr"):1;
	
	if(isset($tab['select-semestr']))
	{
		$default = (int)$tab['select-semestr'];
	}

	for($i=1;$i<=7;$i+=1)
	{
		$semestr[(string)$i] = 'Semestr '.$i;
	}

	
	print '<p>';
	print form::label('select-semestr','<strong>Wybierz semestr</strong>');
	print form::dropdown('select-semestr',$semestr,$default);
	print '</p>';

	print '<p class="buttons">';
	print form::submit(array('type'=>'submit','class'=>'button impotrant'),'Pokaż');
	print " ";
	print form::input(array('class' => 'button', 'type'=>'reset'), 'Ustawienia domyślne');     
	print '</p>';

	print form::close_fieldset();
	print form::close();

	if($_GET)
	{
		$tab = $this->input->get(); 
		$db = new Database;

		if ($db->table_exists('courses'))
		{
			$query = $db->select('DISTINCT courses.*')->from('courses')->where('Sem='.$tab['select-semestr'])->get();
	 	  echo'<h3>Lista kursów: </h3>';
      foreach ($query as $item)
			{
				echo '<p>'.$item->Name.'<br /><strong>'.$item->Code.'</strong></p><br/>';
			}
		}
		else
		{
			echo 'NO! The '.$table.' table doesn\'t exist, so we can\'t continue =( ';
		}
	}
	echo "<br/><br/>\n";
	echo 'done in {execution_time} seconds';    
	
?>

